function connectWebViewJavascriptBridge(callback) {
    if (window.WebViewJavascriptBridge) {
        callback(WebViewJavascriptBridge)
    } else {
        document.addEventListener('WebViewJavascriptBridgeReady', function () {
            callback(WebViewJavascriptBridge);
        }, true);
    }
}

function showAndroid(pid, sid) {
    Android.openGoodDetail(pid, sid);
}
function showAndrobrand(brand_id, brand_name) {
    Android.openBrandList( brand_id, brand_name);
}
window.onload = function () {
    var u = navigator.userAgent, app = navigator.appVersion;
    var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器
    var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
    connectWebViewJavascriptBridge(function (bridge) {

        bridge.init(function (message, responseCallback) {

        });
        $(document).on('click', '.C_J_good_ios', function (e) {
            var pid = $(this).attr('data-id') ? $(this).attr('data-id') : '';
            var sid = $(this).attr('data-sid') ? $(this).attr('data-sid') : '';
            e.preventDefault();
            bridge.callHandler('goDetail', {'pid': pid, sid: sid}, function (response) {

            });
        });
        //跳转到品牌
        $(document).on('click', '.M_brand_i', function (e) {
            var brand_id = $(this).attr('data-id');
            var sid = $(this).attr('data-sid');
            var brand_name = $(this).attr('data-name');
            e.preventDefault();
            bridge.callHandler('goO2oBrand', {'brand_id': brand_id, 'sid': sid, 'brand_name': brand_name}, function (response) {

            });
        });
    });

    if (isAndroid) {
        //单品测试
        $(document).on('click', '.C_J_good', function () {
            var pid = $(this).attr('data-id') ? $(this).attr('data-id') : '';
            console.log(pid);
            var store_id = $(this).attr('data-sid') ? $(this).attr('data-sid') : '';
            //js调用安卓定义方法
            Android.openGoodDetail(pid);
        });

        $(document).on('click', '.M_brand_a', function (e) {
            var brand_id = $(this).attr('data-id') ? $(this).attr('data-id') : '';
            var brand_name = $(this).attr('data-name');
            console.log(brand_id + '==' + brand_name);
            //js调用安卓定义方法
            Android.openBrandList( brand_id, brand_name);
        });
        //分类点击调用(安卓未定义)
        $(document).on('click', '.main_category', function (e) {
            var cate_id = $(this).attr('data-id') ? $(this).attr('data-id') : 1;
            var from_type = $(this).attr('data-type') ? $(this).attr('data-type') : 1;
            var category_name = $(this).attr('data-name');

            console.log(category_name+'==' + cate_id);
            //js调用安卓定义方法
            Android.openCategoryList(cate_id, from_type, category_name);
        });

        //搜索关键词
        $(document).on('click', '.M_T_search', function (e) {
            var keyword = $(this).attr('data-keyword') ? $(this).attr('data-keyword') : '';
            var request_type = 1;
            console.log(keyword);
            Android.openSearchList(keyword);
        });
    }
};